start_node,0
assert_detail,0,leadership_state,Leader
emit_signature,2

assert_detail,0,leadership_state,Leader
assert_commit_idx,0,2

trust_node,2,1
emit_signature,2

dispatch_all
periodic_all,10
dispatch_all
assert_commit_idx,0,4

trust_node,2,2
emit_signature,2

dispatch_all
periodic_all,10
dispatch_all
periodic_all,10
dispatch_all
assert_commit_idx,0,6
assert_state_sync

assert_detail,0,leadership_state,Leader
assert_detail,1,leadership_state,Follower
assert_detail,2,leadership_state,Follower

replicate,2,hello world
emit_signature,2
periodic_all,10
dispatch_all

replicate,2,saluton mondo
emit_signature,2
periodic_all,10
dispatch_all

periodic_all,10
dispatch_all

# All nodes agree so far
state_all
assert_state_sync

# Node 0 is partitioned, and replicates more items
disconnect,0,1
disconnect,0,2

replicate,2,drop me 1
replicate,2,drop me 2
replicate,2,drop me 3
emit_signature,2
periodic_all,10
dispatch_all

state_all

# Node 1 calls an election, and wins
periodic_one,1,110
dispatch_all

periodic_all,10
dispatch_all  #< This AppendEntries starts at a point that Node 1 would accept, but is dropped

state_all

# Node 1 replicates new entries
replicate,3,keep me 1
emit_signature,3
periodic_all,10
dispatch_all

replicate,3,keep me 2
emit_signature,3
periodic_all,10
dispatch_all

state_all

# Nodes 1 and 2 advance multiple terms and new entries
periodic_one,2,110
dispatch_all

periodic_all,10
dispatch_all

replicate,4,keep me term 4
emit_signature,4

periodic_all,10
dispatch_all

periodic_one,1,110
dispatch_all

periodic_all,10
dispatch_all

replicate,5,keep me term 5
emit_signature,5

periodic_all,10
dispatch_all

periodic_all,10
dispatch_all

state_all

# Network heals
connect,0,1
connect,0,2

# Node 0 hears they were deposed
periodic_all,10
dispatch_all
state_all

# Node 1 tries to bring node 0 back in line
# But we get unlucky with timing, and node 1 continually follows up with a heartbeat before hearing the response
# This means it processes a useful NACK and then an unhelpful NACK
periodic_all,10
periodic_one,1,10
dispatch_all

periodic_all,10
periodic_one,1,10
dispatch_all

periodic_all,10
periodic_one,1,10
dispatch_all

state_all
assert_state_sync
